var prefix = jsctx + "/tenantUgsMemberLevel";

var tenantUgsMemberLevel = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 80;

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageTenantUgsMemberLevel",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 20,
                    pageList: [10, 20, 30],
                    pageNumber: 1,
                    sidePagination: "server",
                    height: h,
                    paginationShowPageGo: true,
                    // rightFixedColumns: true,
                    // showColumns: true,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            mobileAndNickName: $("#mobileAndNickName").val().trim(),
                            userLevel: $("#userLevel").val().trim(),
                            memberType: $("#memberType").val().trim()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }, align: 'center'
                        },
                        {field: 'ulmrId', title: '#', visible: false, align: 'center'},
                        {
                            field: 'memberType', title: '会员类型', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '个人'
                                } else if (value == '1') {
                                    return '企业主账户'
                                } else if (value == '2') {
                                    return '企业子账户'
                                } else if (value == '3') {
                                    return '互联互通用户'
                                }
                            }
                        },
                        {field: 'nickname', title: '昵称', align: 'left'},
                        {field: 'mobile', title: '手机号', align: 'left'},
                        {field: 'levelTypeName', title: '会员等级', align: 'center'},
                        {field: 'totoalExpValue', title: '当前经验值', align: 'center'},
                        {field: 'keepValue', title: '保级成长值', align: 'center'},
                        {
                            field: 'distanceKeepValue', title: '距离保级成长值', align: 'center',
                            formatter: function (value, row, index) {
                                if (value < 0) {
                                    return '已保级';
                                } else {
                                    return value;
                                }
                            }
                        },
                        {field: 'maxValue', title: '升级成长值', align: 'center'},
                        {field: 'distanceMaxValue', title: '距离升级成长值', align: 'center'},
                        {field: 'keepTime', title: '当前等级有效期', align: 'left'},
                        {
                            title: '操作',
                            field: 'roleId',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var a = '';
                                if (MemberManager_tenantUgsMemberLevel_look) {
                                    a = '<a class="btn btn-success btn-sm ' + has_edit + '" href="#" title="成长值记录" onclick="tenantUgsMemberLevel.memberLevelRecord(\''
                                        + row.memberId
                                        + '\')">成长值记录</a> ';
                                }
                                return a;
                            }
                        }
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function memberLevelRecord(memberId) {
        location.href = prefix + "/memberLevelRecord/" + memberId;
    }

    return {
        init: init,
        reLoad: reLoad,
        memberLevelRecord: memberLevelRecord
    };
})();
